/*
 * TryReplaceScript.scala
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package trypkg

import java.io._
object TryReplaceScript {
    def main(args : Array[String]) : Unit = {
        val strUrl = "http://finance.sina.com.cn/"
        val in = new InputStreamReader(new java.net.URL(strUrl).openStream)
        var input = new java.lang.StringBuilder
        var c = in.read
        while(c != -1){
            input.append(c.asInstanceOf[Char])
            //println("c= " + c)
            c = in.read
        }
        //        println(input)
        var StyleStart = input.indexOf("<style")
        println("StyleStart = " + StyleStart)
        var StyleEnd = input.indexOf("</style>")
        println("StyleEnd = " + StyleEnd)

        println(input.length)
        try{
            while((input.length > 0) && (StyleStart != -1) && (StyleEnd != -1)){
                input = input.delete(StyleStart, StyleEnd+5)
               
                StyleStart = input.indexOf("<style")
                println("StyleStart = " + StyleStart)
                StyleEnd = input.indexOf("</style>")
                println("StyleEnd = " + StyleEnd)

               
            }
            var ScriptStart = input.indexOf("<script")
            println("ScriptStart = " +ScriptStart)
            var ScriptEnd = input.indexOf("</script>")
            println("ScriptEnd = " + ScriptEnd)

            while((input.length > 0)&& (ScriptEnd != -1)&& (ScriptEnd != -1)){
                input = input.delete(ScriptStart, ScriptEnd+9)
                
                ScriptStart = input.indexOf("<script")
                println("ScriptStart = " +ScriptStart)
                ScriptEnd = input.indexOf("</script>")
                println("ScriptEnd = " + ScriptEnd)

                println(input.length)
            }
        }catch{
            case e : Exception =>{
                    println(e.toString)
                }
        }
        println(input)
    }
}
